package ab.mes.controller;

import ab.mes.entity.Bin;
import ab.mes.entity.FinishedProductBin;
import ab.mes.entity.FinishedProductBinStock;
import ab.mes.service.FinishedProductBinService;
import ab.mes.service.impl.BinServiceImpl;
import ab.mes.service.impl.FinishedProductBinServiceImpl;
import ab.mes.service.impl.FinishedProductBinStockServiceImpl;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/finishedProductBinStock")
public class FinishedProductBinStockController {
    @Autowired
    private FinishedProductBinStockServiceImpl finishedProductBinStockService;

    //查询物料库位信息
    @PostMapping("/getFinishedProductBinStock")
    public Result getFinishedProductBinStock(){
        Result result=new Result();
        try {
            result = finishedProductBinStockService.getFinishedProductBinStock();
        }catch (Exception e){
            result.setErrorMessage("查询物料库位失败！");
            e.printStackTrace();
        }
        return result;
    }

    //查询库位编号物料库位信息
    @PostMapping("/getFinishedProductBinStockById")
    public Result getFinishedProductBinStockById(String Id){
        Result result=new Result();
        try {
            result = finishedProductBinStockService.getFinishedProductBinStockById(Id);
        }catch (Exception e){
            result.setErrorMessage("查询库位失败！");
            e.printStackTrace();
        }
        return result;
    }


    //编辑库位
    @PostMapping("/editFinishedProductBinStock")
    public Result editFinishedProductBinStock(@RequestBody FinishedProductBinStock finishedProductBinStock){
        Result result=new Result();
        try {
            finishedProductBinStockService.editFinishedProductBinStock(finishedProductBinStock);
        }catch (Exception e){
            result.setErrorMessage("编辑失败！");
            e.printStackTrace();
        }
        return result;
    }

    //新增库位
    @PostMapping("/insertFinishedProductBinStock")
    public Result insertFinishedProductBinStock(@RequestBody FinishedProductBinStock finishedProductBinStock){
        Result result=new Result();
        try {
            finishedProductBinStockService.insertFinishedProductBinStock(finishedProductBinStock);
        }catch (Exception e){
            result.setErrorMessage("新增失败！");
            e.printStackTrace();
        }
        return result;
    }
}
